#include <xmlrpc-c/base.h>
#include <xmlrpc-c/server.h>
#include <xmlrpc-c/server_abyss.h>

#include <set>
#include <string>

#include "exception.h"
#include "ifeedreader_engine.h"

using namespace std;


#define FR_RPC xmlrpc_value*
#define FR_RPC_PARAMS \
	(	\
		xmlrpc_env* 	env,	\
		xmlrpc_value*	param_array,	\
		void*		serverInfo	\
	)


class FeedReaderXmlRpcSupport
{
public:
	class AlreadyRunningException 	: Exception {};
	class NotRunningException	: Exception {};
	
	static void Run  ( IFeedReaderEngine* engine , int port );
	static void Stop ();

private:
	FeedReaderXmlRpcSupport();

	static FR_RPC GetTags		FR_RPC_PARAMS;
	static FR_RPC GetFeeds		FR_RPC_PARAMS;
	static FR_RPC GetFeedByNumber	FR_RPC_PARAMS;
	static FR_RPC GetNewsByNumber	FR_RPC_PARAMS;
	static FR_RPC GetNews		FR_RPC_PARAMS;

	static FR_RPC AddTag		FR_RPC_PARAMS;
	static FR_RPC DelTag		FR_RPC_PARAMS;
	
	static FR_RPC AddFeed		FR_RPC_PARAMS;
	static FR_RPC DelFeed		FR_RPC_PARAMS;

	static FR_RPC AssignTags	FR_RPC_PARAMS;
	static FR_RPC RemoveTags	FR_RPC_PARAMS;
		
	static FR_RPC Search		FR_RPC_PARAMS;
	
	static IFeedReaderEngine* Engine;

	static xmlrpc_value* 	MakeNewsArray(xmlrpc_env* env,list<__News*>& news);
	static set<int>		MakeIntSet(xmlrpc_env* env,xmlrpc_value* param);
};

